package com.ezops.dao.facade;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ezops.dao.generics.dao.hibernate.GenericDAO;
import com.ezops.dao.generics.search.Search;
import com.ezops.models.Asset;

@Service
public class AssetDataTransferFacade extends DataTransferFacadeImpl<Asset>
		implements IAssetDataTransferFacade {

	@Autowired
	private GenericDAO<Asset, Serializable> dao;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ezops.dao.facade.IAssetDataTransferFacade#lookUp(java.lang.String)
	 */
	@Override
	public int lookUp(String name) {
		Search searchCriteria = new Search(Asset.class);
		searchCriteria.addFilterEqual("assetName", name.toLowerCase());
		//TODO - when the Domain entity change to {@code int getId()} chnage this code as well.
		return Integer.parseInt(((Asset) dao.search(searchCriteria).get(0)).getId());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.ezops.dao.facade.IAssetDataTransferFacade#reverseLookUp(int)
	 */
	@Override
	public String reverseLookUp(int id) {
		Search searchCriteria = new Search(Asset.class);
		searchCriteria.addFilterEqual("assetId", id);
		return ((Asset) dao.search(searchCriteria).get(0)).getAssetName();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.ezops.dao.facade.IAssetDataTransferFacade#getAllAssets()
	 */
	@Override
	public List<Asset> getAllAssets() {
		return dao.findAll();
	}

	@Override
	public GenericDAO<Asset, Serializable> getDataAccessObject() {
		return dao;
	}

}
